package com.game.majiang.vo;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import javax.sql.rowset.CachedRowSet;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import net.sf.json.JSONArray;

import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;

@Log4j
@Data
public class ParameterVo {
	

	public static HashMap<String,String> getList() {
		HashMap<String,String> map = new HashMap<String,String>();
		String sql = "select name,value from parameter";
		CachedRowSet rs = SqlHelper.getResultSet(sql);
		try {
			while (rs.next()) 
			{  
				String key  = rs.getString(1);
				String value  = rs.getString(2);
				map.put(key, value);								
			}
		} catch (SQLException e) {
			e.printStackTrace();
			log.warn("Sql:" + sql + "错误");
		}
		log.info("Sql:{}"+map);
		return map;
	}
	public static HashMap<String,Integer> getListParameterServerType() {
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		String sql = "select name,servertype from parameter";
		CachedRowSet rs = SqlHelper.getResultSet(sql);
		try {
			while (rs.next()) 
			{  
				String key  = rs.getString(1);
				int value  = rs.getInt(2);
				map.put(key, value);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			log.warn("Sql:" + sql + "错误");
		}
		return map;
	}
	public static void updatejinyan1(String val)
	{
		String sql = "update parameter set value=? where name = 'jyaplayers1'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updatejinyan2(String val)
	{
		String sql = "update parameter set value=? where name = 'jyaplayers2'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updatejinyan3(String val)
	{
		String sql = "update parameter set value=? where name = 'jyaplayers3'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updatejinyin1(String val)
	{
		String sql = "update parameter set value=? where name = 'jyiplayers1'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updatejinyin2(String val)
	{
		String sql = "update parameter set value=? where name = 'jyiplayers2'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updatejinyin3(String val)
	{
		String sql = "update parameter set value=? where name = 'jyiplayers3'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updateTIMETYPE(String val)
	{
		String sql = "update parameter set value=? where name = 'TIMETYPE'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
	public static void updateclearrankinglist(String val)
	{
		String sql = "update parameter set value=? where name = 'clearrankinglist'";
		Parameter p1 = new Parameter(Types.VARCHAR, val, ParameterType.Input);

		SqlHelperwrite.execute(sql, p1);
	}
}
